package com.dick.base.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dick.base.model.BusinessSpecification;
import com.dick.base.parameter.SpecificationParameter;
import com.dick.base.service.SpecificationService;
import com.dick.base.util.BaseResult;
import com.dick.base.util.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 规格管理api
 */
//@RestController
@RequestMapping(path = "api/specifications")
public class SpecificationApi {

    @Autowired
    private SpecificationService specificationService;

    @ApiOperation(value = "规格分页查询", tags = "规格管理")
    @GetMapping("page")
    public BaseResult<Page<BusinessSpecification>> specificationPage(BusinessSpecification specification, PageInfo pageInfo) {
        return BaseResult.of(specificationService.specificationPage(specification, pageInfo));
    }

    @ApiOperation(value = "规格详情", tags = "规格管理")
    @GetMapping("{id}")
    public BaseResult<BusinessSpecification> specificationDetail(@PathVariable Long id) {
        return BaseResult.of(specificationService.businessSpecificationDetail(id));
    }

    @ApiOperation(value = "规格添加", tags = "规格管理")
    @PostMapping
    public BaseResult<Void> addSpecification(@Valid @RequestBody SpecificationParameter specificationParameter) {
        specificationService.addSpecification(specificationParameter);
        return BaseResult.voidResult();
    }

    @ApiOperation(value = "规格弃用", tags = "规格管理")
    @PostMapping("delete")
    public BaseResult<Void> removeSpecification(@RequestParam Long id) {
        specificationService.removeSpecification(id);
        return BaseResult.voidResult();
    }
}
